package com.qk.mapper;


import com.qk.dto.ActivitiesDto;
import com.qk.entity.Activity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ActivityMapper {

    List<Activity> listActivities(ActivitiesDto activitiesDto);
//2、添加活动
    @Insert("INSERT INTO activity(id, name, channel, start_time, end_time, description, type, discount, voucher, create_time, update_time) " +
            "VALUES(#{id}, #{name}, #{channel}, #{startTime}, #{endTime}, #{description}, #{type}, #{discount}, #{voucher}, #{createTime}, #{updateTime})")
    void addActivity(Activity activity);
//3、根据id查询活动
    @Select("SELECT * FROM activity WHERE id = #{id}")
//根据id查询活动
    Activity getById(Integer id);
//修改活动
    @Insert("UPDATE activity SET name = #{name}, channel = #{channel}, start_time = #{startTime}, end_time = #{endTime}, description = #{description}, type = #{type}, discount = #{discount}, voucher = #{voucher}, update_time = #{updateTime} WHERE id = #{id}")
    void update(Activity activity);
//查询指定类型的活动
    @Select("SELECT * FROM activity WHERE type = #{type}")
    List<Activity> getActivitesByType(Integer type);
//删除活动
    @Delete("DELETE FROM activity WHERE id = #{id}")
    void deleteById(Integer id);
//查询所有活动
    @Select("SELECT * FROM activity")
    List<Activity> list();
}
